package com.hmily.dubbo.consumer.sync;

import com.hmily.dubbo.api.UserValidationFacade;
import com.hmily.dubbo.api.bean.ValidateUserInfo;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;

import java.io.IOException;

/**
 * <h1>通过声明 validation 来基于 Filter 实现验证</h1>
 *
 * @author hmilyylimh
 *         ^_^
 * @version 0.0.1
 *         ^_^
 * @date 2021-11-07
 *
 */
public class ValidationConsumerApplication {

    public static void main(String[] args) throws IOException {
        // 设置应用服务名称
        ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-consumer");
        // 设置注册中心的地址
        RegistryConfig registryConfig = new RegistryConfig("zookeeper://127.0.0.1:2181");

        // 创建引用 UserValidationFacade 这个服务的对象
        ReferenceConfig<UserValidationFacade> referenceConfig = new ReferenceConfig<>();
        referenceConfig.setApplication(applicationConfig);
        referenceConfig.setRegistry(registryConfig);
        referenceConfig.setInterface(UserValidationFacade.class);
        referenceConfig.setValidation("true");

        // 直接拿到引用的代理对象，然后进行远程调用
        UserValidationFacade userValidationFacade = referenceConfig.get();

        ValidateUserInfo userInfo = new ValidateUserInfo();
        userInfo.setId("G314");
        userInfo.setName("yuki");
        System.out.println(userValidationFacade.validateUser(userInfo));

        // 阻塞等待
        System.in.read();
    }
}
